using System;
using NUnit.Framework;
using DotNetXmlSwfChart;

namespace DotNetXmlSwfChart.UnitTest
{
    [TestFixture]
    public class DrawTextFixture
    {
        [Test]
        public void DrawTextBackgroundLayerDissolveTransitionCenterBottom()
        {
            TextTest(DrawLayer.background, TransitionType.dissolve, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerDissolveTransitionLeftMiddle()
        {
            TextTest(DrawLayer.foreground, TransitionType.dissolve, TextHAlign.left, TextVAlign.middle);
        }

        [Test]
        public void DrawTextBackgroundLayerDropTransition()
        {
            TextTest(DrawLayer.background, TransitionType.drop, TextHAlign.right, TextVAlign.top);
        }

        [Test]
        public void DrawTextForegroundLayerDropTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.drop, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextBackgroundLayerSpinTransition()
        {
            TextTest(DrawLayer.background, TransitionType.spin, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerSpinTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.spin, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextBackgroundLayerScaleTransition()
        {
            TextTest(DrawLayer.background, TransitionType.scale, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerScaleTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.scale, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextBackgroundLayerZoomTransition()
        {
            TextTest(DrawLayer.background, TransitionType.zoom, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerZoomTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.zoom, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextBackgroundLayerBlinkTransition()
        {
            TextTest(DrawLayer.background, TransitionType.blink, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerBlinkTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.blink, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextBackgroundLayerSlideRightTransition()
        {
            TextTest(DrawLayer.background, TransitionType.slide_right, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerSlideRightTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.slide_right, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextBackgroundLayerSlideLeftTransition()
        {
            TextTest(DrawLayer.background, TransitionType.slide_left, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerSlideLeftTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.slide_left, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextBackgroundLayerSlideUpTransition()
        {
            TextTest(DrawLayer.background, TransitionType.slide_up, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerSlideUpTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.slide_up, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextBackgroundLayerSlideDownTransition()
        {
            TextTest(DrawLayer.background, TransitionType.slide_down, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerSlideDownTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.slide_down, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextBackgroundLayerNoTransition()
        {
            TextTest(DrawLayer.background, TransitionType.none, TextHAlign.center, TextVAlign.bottom);
        }

        [Test]
        public void DrawTextForegroundLayerNoTransition()
        {
            TextTest(DrawLayer.foreground, TransitionType.none, TextHAlign.center, TextVAlign.bottom);
        }

        private void TextTest(DrawLayer layer, TransitionType type, TextHAlign halign, TextVAlign valign)
        {
            string testXml =
                "<text layer='{0}' " +
                      "transition='{1}' " +
                      "delay='1.2' " +
                      "duration='2.2' " +
                      "x='20' " +
                      "y='40' " +
                      "width='100' " +  
                      "height='200' " +
                      "h_align='{2}' " + 
                      "v_align='{3}' " +
                      "rotation='10' " +
                      "font='Arial' " +
                      "bold='True' " +
                      "size='10' " +
                      "color='ffffff' " + 
                      "alpha='2'>" +
                      "text to draw</text>";
            DrawText text = new DrawText();
            text.Layer = layer;
            text.Transition = type;
            text.Delay = 1.2;
            text.Duration = 2.2;
            text.X = 20;
            text.Y = 40;
            text.Width = 100;
            text.Height = 200;
            text.HAlign = halign;
            text.VAlign = valign;
            text.Rotation = 10;
            text.Font = "Arial";
            text.Bold = true;
            text.Size = 10;
            text.Color = "ffffff";
            text.Alpha = 2;
            text.Text = "text to draw";
            Assert.AreEqual(
                string.Format(testXml, layer.ToString(), type.ToString(), halign.ToString(), valign.ToString()),
                text.ToSourceXML());
        }
    }
}
